<template>
  <div>
    <el-breadcrumb separator-class="el-icon-arrow-right">
      <el-breadcrumb-item :to="{ path: '/home' }">首页</el-breadcrumb-item>
      <el-breadcrumb-item>商品管理</el-breadcrumb-item>
      <el-breadcrumb-item>商品列表</el-breadcrumb-item>
    </el-breadcrumb>

    <el-card>
      <el-row>
        <el-col :span="13">
          <el-input placeholder="请输入内容" class="input-with-select">
            <el-button slot="append" icon="el-icon-search"></el-button>
          </el-input>
        </el-col>

        <el-col :span="3" :offset="1">
          <el-button>添加商品</el-button>
        </el-col>
      </el-row>

      <el-table :data="goodsList">
        <el-table-column type="index"></el-table-column>
        <el-table-column prop="goods_name" label="商品名称" width="500"></el-table-column>
        <el-table-column prop="goods_price" label="商品价格"></el-table-column>
        <el-table-column prop="goods_weight" label="商品重量"></el-table-column>
        <el-table-column label="创建时间">
            <template slot-scope="scope">
                <p>{{scope.row.add_time |timer() }}</p>
            </template>
        </el-table-column>
        <el-table-column labe l="操作">
          <template slot-scope="scope">
            
            <el-button
              type="primary"
              size="mini"
              icon="el-icon-edit"
              circle
            ></el-button>

            <el-buttond
              type="danger"
              size="mini"
              icon="el-icon-delete"
              circle
            ></el-button>
          </template>
        </el-table-column>
      </el-table>

      <el-pagination
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="getGoodsParams.pagenum"
        :page-sizes="[10, 20, 30, 40]"
        :page-size="getGoodsParams.pagesize"
        layout="total, sizes, prev, pager, next, jumper"
        :total="total"
      >
      </el-pagination>
    </el-card>
  </div>
</template>

<script>
import { getgoods } from "@/http/goods.js";
export default {
  data() {
    return {
      goodsList: [{}],
 
      getGoodsParams: {
        query: "",
        pagenum: 1,
        pagesize: 10,
      },
      total:0
    };
  },

  mounted() {
    this.getGoodsList();
  },

  methods: {
    handleSizeChange(val) {
      console.log(`每页 ${val} 条`);
      this.getGoodsParams.pagesize=val;
      this.getGoodsList();

    },
    handleCurrentChange(val) {
      console.log(`当前页: ${val}`);
       this.getGoodsParams.pagenum=val;
      this.getGoodsList();
    },
    async getGoodsList() {
      let res = await getgoods(this.getGoodsParams);
      console.log(res);
      this.goodsList=res.data.goods;
      this.total =res.data.total
    },
  },
};
</script>

<style lang="scss" scoped>
</style>